#include "RK_Info.h"

RK_Info::RK_Info() {
	__A = NULL;
	__B = NULL;
	__C = NULL;
	__S = 0;
};

RK_Info::RK_Info(const std::size_t _s) {
	__A = new double [_s*(_s - 1)/2];
	__B = new double [_s];
	__C = new double [_s];
	__S = _s;
};

RK_Info::RK_Info(const double *_a, const double *_b, const double *_c, const std::size_t _s) {
	__A = new double [_s*(_s - 1)/2];
	__B = new double [_s];
	__C = new double [_s];
	__S = _s;
	for(int i = 0; i != _s; i++) {
		__B[i] = _b[i];
		__C[i] = _c[i];
	}
	for(int i = 0; i != _s*(_s - 1)/2; i++) {
		__A[i] = _a[i];
	}
};

RK_Info::~RK_Info() {
	if(__A != NULL) {
		delete [] __A;
	}
	if(__B != NULL) {
		delete [] __B;
	}
	if(__C != NULL) {
		delete [] __C;
	}
};

const double RK_Info::get_a_i(const std::size_t _i) const {
	if(_i > __S*(__S - 1)/2 - 1) {
		std::cerr << "Out of range when getting LLM_Info's __A_i'!" << std::endl;
		std::exit(-1);
	}
	return __A[_i];
};

const double RK_Info::get_b_i(const std::size_t _i) const {
	if(_i > __S - 1) {
		std::cerr << "Out of range when getting LLM_Info's __B_i'!" << std::endl;
		std::exit(-1);
	}
	return __B[_i];
};

const double RK_Info::get_c_i(const std::size_t _i) const { 
	if(_i > __S - 1) {
		std::cerr << "Out of range when getting LLM_Info's __C_i'!" << std::endl;
		std::exit(-1);
	}
	return __C[_i];
};

const std::size_t RK_Info::get_s() const {
	return __S;
};
	
void RK_Info::set_info(const double *_a, const double *_b, const double *_c, const std::size_t _s) {
	__A = new double [_s*(_s - 1)/2];
	__B = new double [_s];
	__C = new double [_s];
	for(int i = 0; i != _s; i++){
		__B[i] = _b[i];
		__C[i] = _c[i];
		__S = _s;
	}
	for(int i = 0; i != _s*(_s - 1)/2; i++) {
		__A[i] = _a[i];
	}
};

const RK_Info& RK_Info::operator=(const RK_Info &_rk_info) {
	std::size_t s = _rk_info.get_s();
	if(this != &_rk_info) {
		__A = new double [s*(s - 1)/2];
		__B = new double [s];
		__C = new double [s];
		for(int i = 0; i != s; i++){
			__B[i] = _rk_info.get_b_i(i);
			__C[i] = _rk_info.get_c_i(i);
			__S = s;
		}
		for(int i = 0; i != s*(s - 1)/2; i++) {
			__A[i] = _rk_info.get_a_i(i);
		}
	}
	return *this;
};


